#ifndef ICOM_H
#define ICOM_H

#include <QObject>

class ComMessage : public QObject
{
	Q_OBJECT

public:
	ComMessage() { }

	ComMessage(QByteArray &ba)
	{
		this->m_data = ba;
	}

	char at(const int i) const
	{
		return this->m_data.at(i);
	}

	inline void resize(const int size)
	{
		this->m_data.resize(size);
	}

	inline char* data()
	{
		return this->m_data.data();
	}

	inline int size() const
	{
		return this->m_data.size();
	}

	inline bool empty() const
	{
		return this->m_data.size() == 0;
	}

	void set(QByteArray &ba)
	{
		this->m_data = ba;
	}

	ComMessage& operator = (ComMessage& msg)
	{
		this->m_data = msg.m_data;
		return *this;
	}

	QString m_target;

private:
	QByteArray m_data;
};

class ICom : public QObject
{
	Q_OBJECT

public:
	int timeout;

	ICom() :timeout(1000) {}

	virtual bool IsConnected() = 0;

	virtual bool Connect(char *port = nullptr, char *args = nullptr) = 0;
	virtual bool Disconnect() = 0;

	virtual int GetChar(int timeout = -1) = 0;
	virtual void PutChar(char c) = 0;

	virtual int GetPacket(ComMessage &message, int timeout = -1) = 0;
	virtual void PutPacket(ComMessage &message) = 0;
};

#endif // ICOM_H
